package defpackage; import android.support.v4.app.NotificationCompat; import cn.wps.moffice.OfficeApp; import cn.wps.moffice_eng.R; import com.baidu.tts.loopj.AsyncHttpResponseHandler; import com.google.firebase.analytics.FirebaseAnalytics; import com.iflytek.cloud.SpeechEvent; import defpackage.ghu; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import org.json.JSONException; import org.json.JSONObject; /* renamed from: gks reason: default package */ public final class gks { private static boolean k(JSONObject jSONObject) { if (jSONObject != null) { try { return FirebaseAnalytics.Param.SUCCESS.equals(jSONObject.get(NotificationCompat.CATEGORY_MESSAGE)) && jSONObject.has(SpeechEvent.KEY_EVENT_RECORD_DATA); } catch (JSONException e) { } } } private List<gkr> l(JSONObject jSONObject) { gkr[] gkrArr; try { if (k(jSONObject) && (gkrArr = (gkr[]) lvb.b(jSONObject.getString(SpeechEvent.KEY_EVENT_RECORD_DATA), gkr[].class)) != null) { ArrayList arrayList = new ArrayList(); for (gkr gkr : gkrArr) { arrayList.add(gkr); } return arrayList; } } catch (Exception e) { e.printStackTrace(); } return null; } private static String wg(String str) { StringBuilder sb = new StringBuilder(); try { sb.append("https://dynamicedu.wps.cn/API_V2/freevideo/search/v2?client=2&keyword="); try { sb.append(URLEncoder.encode(str.trim(), AsyncHttpResponseHandler.DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return lwd.f(sb.toString(), null); } catch (Exception e2) { e2.printStackTrace(); return ""; } } public final List<ghu> R(String str, int i) { boolean z; int i2 = 0; try { ArrayList arrayList = new ArrayList(); JSONObject jSONObject = new JSONObject(wg(str)); if (!FirebaseAnalytics.Param.SUCCESS.equalsIgnoreCase(jSONObject.optString(NotificationCompat.CATEGORY_MESSAGE))) { return null; } List<gkr> l = l(jSONObject); if (l == null || l.size() <= 0) { if (i == 3 || i == 1) { ghu ghu = new ghu(); ghu.gEV = 2; ghu.extras = new ArrayList(); ghu.extras.add(new ghu.a("keyword", str)); ghu.extras.add(new ghu.a(NotificationCompat.CATEGORY_STATUS, Integer.valueOf(i))); arrayList.add(ghu); } return null; } ArrayList arrayList2 = new ArrayList(); int i3 = 0; while (i3 < l.size() && i3 <= 3) { arrayList2.add(l.get(i3)); i3++; } if ((i == 1 || i == 3) && arrayList2.size() > 3) { arrayList2.remove(arrayList2.size() - 1); z = true; } else { z = false; } while (i2 < arrayList2.size() && ((i == 1 && i2 <= 3) || i == 3)) { ghu ghu2 = new ghu(); ghu2.gEV = 13; ghu2.extras = new ArrayList(); ghu2.extras.add(new ghu.a("object", arrayList2.get(i2))); ghu2.extras.add(new ghu.a("keyword", str)); ghu2.extras.add(new ghu.a(NotificationCompat.CATEGORY_STATUS, Integer.valueOf(i))); arrayList.add(ghu2); i2++; } if (arrayList.size() > 0 && (i == 1 || i == 3)) { ghu ghu3 = new ghu(); ghu3.gEV = 2; ghu3.extras = new ArrayList(); ghu3.extras.add(new ghu.a("keyword", str)); ghu3.extras.add(new ghu.a(NotificationCompat.CATEGORY_STATUS, Integer.valueOf(i))); ghu3.extras.add(new ghu.a("header", OfficeApp.arx().getString(R.string.public_search_wps_skill))); ghu3.extras.add(new ghu.a("header_no_bottom", true)); arrayList.add(0, ghu3); ghu ghu4 = new ghu(); ghu4.gEV = 3; ghu4.extras = new ArrayList(); ghu4.extras.add(new ghu.a("keyword", str)); ghu4.extras.add(new ghu.a(NotificationCompat.CATEGORY_STATUS, Integer.valueOf(i))); if (z) { ghu4.extras.add(new ghu.a("bottom", OfficeApp.arx().getString(R.string.phone_home_new_search_more_documents))); ghu4.extras.add(new ghu.a("jump_to", 1)); } else { ghu4.extras.add(new ghu.a("bottom", OfficeApp.arx().getString(R.string.public_search_more_skill))); ghu4.extras.add(new ghu.a("jump_to", 0)); } ghu4.extras.add(new ghu.a("jump", "jump_wps_skill")); arrayList.add(ghu4); } return arrayList; } catch (Exception e) { } } }